home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-05-14 | 6.2 KB | 244 lines |
- import ComponentApp;
- import java.lang.Integer;
-
- public class TickerTapeComp extends ComponentApp
- {
- int Speed;
- int Frame;
- int Background;
- int LED;
- int numImages;
- int MaxImages;
- DAssetManager assetMan;
- DDrawJava theJavaApplet;
- String[] imageNames;
- int[] imageURLs;
-
- public void onCopy()
- {
- String[] imageNamesOld = imageNames;
- int[] imageURLsOld = imageURLs;
-
- allocateImageArray(MaxImages);
- for(int cnt=0;cnt<numImages;cnt++)
- {
- imageNames[cnt] = new String(imageNamesOld[cnt]);
- if(imageURLsOld[cnt] !=0 && imageURLsOld[cnt] != -1)
- {
- imageURLs[cnt] = imageURLsOld[cnt];
- assetMan.CopyAsset(imageURLsOld[cnt]);
- }
- }
- }
-
- protected void finalize()
- {
- for(int cnt=0;cnt<numImages;cnt++)
- {
- if(imageURLs[cnt] !=0 && imageURLs[cnt] != -1)
- assetMan.RemoveAsset(imageURLs[cnt]);
- }
- }
- public String onInstall(DAssetManager cam, String codeBase)
- {
- MaxImages=50;
- assetMan = cam;
- return "Ticker Tape";
- }
-
- public void onInspect(CStringArray Names,CStringArray Types)
- {
- Names.Set("Number of Messages");
- Types.Set(typeJavaCollection);
- for(int cnt=0; cnt<numImages; cnt++)
- {
- Names.Set("Text for Message "+Integer.toString(cnt+1));
- Types.Set(typeString);
- Names.Set("URL for Message "+Integer.toString(cnt+1));
- Types.Set(typeLink);
- }
- Names.Set("Speed");
- Types.Set(typeJavaCollection);
- Names.Set("Frame Color");
- Types.Set(typeJavaColor);
- Names.Set("Background Color");
- Types.Set(typeJavaColor);
- Names.Set("LED Color");
- Types.Set(typeJavaColor);
- }
-
- public String PropertyListener(String Event,String Value,int Get, int propIndex, IDInspector insp)
- {
- if (Get == 1)
- {
- if (Event.compareTo("Number of Messages") == 0)
- {
- return Integer.toString(numImages);
- }
- else if (Event.compareTo("Speed") == 0)
- {
- return Integer.toString(Speed);
- }
- else if (Event.compareTo("Frame Color") == 0)
- {
- return Integer.toString(Frame);
- }
- else if (Event.compareTo("Background Color") == 0)
- {
- return Integer.toString(Background);
- }
- else if (Event.compareTo("LED Color") == 0)
- {
- return Integer.toString(LED);
- }
- else
- {
- for(int cnt=0; cnt<numImages; cnt++)
- {
- if (Event.compareTo("Text for Message "+Integer.toString(cnt+1))==0)
- return new String(imageNames[cnt]);
- if (Event.compareTo("URL for Message "+Integer.toString(cnt+1))==0)
- return Integer.toString(imageURLs[cnt]);
- }
- }
- }
- else
- {
- if (Event.compareTo("Number of Messages") == 0)
- {
- numImages=Integer.parseInt(Value,10);
- if(numImages>MaxImages)
- numImages=MaxImages;
- }
- else if (Event.compareTo("Speed") == 0)
- {
- Speed = Integer.parseInt(Value,10);
-
- if (Speed < 1)
- Speed = 1;
- else if (Speed > 50)
- Speed = 50;
-
- theJavaApplet.AddParam("speed",typeInt,Integer.toString(Speed));
- }
- else if (Event.compareTo("Frame Color") == 0)
- {
- Frame = Integer.parseInt(Value,10);
- SetColor("framecolor",Frame);
- }
- else if (Event.compareTo("Background Color") == 0)
- {
- Background = Integer.parseInt(Value,10);
- SetColor("backcolor",Background);
- }
- else if (Event.compareTo("LED Color") == 0)
- {
- LED = Integer.parseInt(Value,10);
- SetColor("ledcolor",LED);
- }
- else
- {
- for(int cnt=0; cnt<numImages; cnt++)
- {
- if (Event.compareTo("Text for Message "+Integer.toString(cnt+1))==0)
- {
- imageNames[cnt]=Value;
- theJavaApplet.AddParam("text"+Integer.toString(cnt+1),typeString,Value);
- }
- if (Event.compareTo("URL for Message "+Integer.toString(cnt+1))==0)
- {
- imageURLs[cnt]=Integer.parseInt(Value,10);
- String theURL;
- if(imageURLs[cnt]!=-1)
- {
- theURL=assetMan.GetAssetLocation(imageURLs[cnt], 0, IFileNameStyle.DosName);
- }
- else
- {
- theURL="";
- }
- theJavaApplet.AddParam("link"+Integer.toString(cnt+1),typeString,theURL);
- }
- }
- }
- }
- return "";
- }
-
- void allocateImageArray(int n) {
-
- imageNames=new String[n];
- imageURLs=new int[n];
- for(int cnt=0;cnt< n;cnt++)
- {
- imageURLs[cnt]=-1;
- imageNames[cnt] = "";
- }
- }
-
- public void onDrop(IDLayout layout, IDRect r, int fDrop)
- {
- //
- // we only process drop for now
- //
- if (fDrop != ActivateState.Drop) // the first time the component is dropped
- return;
-
- numImages=2;
-
- Speed = 25;
- Frame = 6;
- Background = 0;
- LED = 5;
-
- allocateImageArray(MaxImages);
- theJavaApplet = new DDrawJava();
- theJavaApplet.setImageFile(theJavaApplet.getCodeBase() + "TickerTape.jpg");
- theJavaApplet.setStretch(PictureStretchMode.DRAW_STRETCHED);
- theJavaApplet.setAppletFileName(theJavaApplet.getCodeBase() + "TickerTape.class");
- theJavaApplet.SetPositionRect(r.getLeft(), r.getTop(), r.getRight(), r.getBottom());
- layout.AddObject(theJavaApplet);
-
- }
-
- public void onUnInstall(DAssetManager cam)
- {
- }
-
- public void onPublish(DAssetManager asm, int context)
- {
- }
-
- private void SetColor(String VarName,int SetVal)
- {
- if (SetVal == 0)
- theJavaApplet.AddParam(VarName,typeString,"black");
- else if (SetVal == 1)
- theJavaApplet.AddParam(VarName,typeString,"blue");
- else if (SetVal == 2)
- theJavaApplet.AddParam(VarName,typeString,"cyan");
- else if (SetVal == 3)
- theJavaApplet.AddParam(VarName,typeString,"darkGray");
- else if (SetVal == 4)
- theJavaApplet.AddParam(VarName,typeString,"gray");
- else if (SetVal == 5)
- theJavaApplet.AddParam(VarName,typeString,"green");
- else if (SetVal == 6)
- theJavaApplet.AddParam(VarName,typeString,"lightGray");
- else if (SetVal == 7)
- theJavaApplet.AddParam(VarName,typeString,"magenta");
- else if (SetVal == 8)
- theJavaApplet.AddParam(VarName,typeString,"orange");
- else if (SetVal == 9)
- theJavaApplet.AddParam(VarName,typeString,"pink");
- else if (SetVal == 10)
- theJavaApplet.AddParam(VarName,typeString,"red");
- else if (SetVal == 11)
- theJavaApplet.AddParam(VarName,typeString,"white");
- else if (SetVal == 12)
- theJavaApplet.AddParam(VarName,typeString,"yellow");
- }
-
-
- }
-